if (get_cookie("key")) {
    $.ajax({
        url: ip + "index.php?s=admincms/login/isadmin",
        type: "post",
        data: {
            "user": get_cookie("user"),
            "key": get_cookie("key")
        },
        success: function (_res) {
            res = JSON.parse(_res);
            if (res.resStatus === 0) {
                // 用户写入页面
                $("#user_name").text(res.data[0].NickName);
                $(".content_left>ul").empty();
                var url=location.href;
                var tiao=true;
                $.each(res.data[0].power_list,function (i,o) {
                    if(url.indexOf(o.url)!==-1){
                        tiao=false;
                    }
                    var _background_=  url.indexOf(o.url)!==-1?'style="background:#000;"':"";

                    $(".content_left>ul").append('<a href="'+o.url+'"> <li '+_background_+'><span class="glyphicon '+o.icon+'"></span><p>'+o.names+'</p></li></a>');

                });

                if(tiao){
                    location.href=res.data[0].power_list[0].url;
                }
            }
            if (res.resStatus === 1) {
                location.href = key_address;
            }
        },
        error: function () {
            location.href = key_address;
        }
    });
} else {
    location.href = key_address;
}
if (!localStorage.arr_danwei) {
    localStorage.arr_danwei = JSON.stringify([]);
}
if (!localStorage.arr_chicun) {
    localStorage.arr_chicun = JSON.stringify([]);
}
if (!localStorage.arr_color) {
    localStorage.arr_color = JSON.stringify([]);
}
$(function () {
    var houtai = {
        //防止频繁操作
        old_click_time: 1000,
        click_yes: function () {
            var now_tiem = new Date().getTime();
            if (now_tiem - houtai.old_click_time > 1000) {
                houtai.old_click_time = now_tiem;
                return true;
            } else {
                return false;
            }
        },
        linshi_search: {
            class1: "",
            class2: "",
            state: "",
            search: "",
            type:"",
            time_start:"",
            time_end:"",
            supplier:"",
            types:""
        },
        linshi_id: null,
        linshi_img_id: null,
        linshi_arrid: [],
        queren_type: null,//0删除 1上架 2下架 3全部上架 4全部下架 5删除图片 6上热卖 7下热卖 8删除详情图片
        list_ajax_page:1,
        // 导出excel
        excel:(function () {
            var uri = 'data:application/vnd.ms-excel;base64,',
                template = '<html  xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta charset="UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
                base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))); },
                format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }); };
            return function (table, name) {
                if (!table.nodeType) table = document.getElementById("tableExcel");
                var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML };
                if($("#dlink").length<1) $("body").append($("<a id='dlink' style='display: none'></a>"));
                document.getElementById("dlink").href = uri + base64(format(template, ctx));
                document.getElementById("dlink").download = name+'.xls';
                document.getElementById("dlink").click();
            };
        })(),
        //提示功能
        hint:function (str) {
            $(".hint").remove();
            $("body").append("<div class='hint'>"+str+"</div>");
            $(".hint").slideDown(300).delay(2000).slideUp();
        },
        jiancha: function () {
            // 判断是够为空
            for (var i = 0; i < $(".add_goods_body .input_is:visible").length; i++) {
                if ($(".add_goods_body .input_is:visible").eq(i).val() === "") {
                    $(".add_goods_body .input_is:visible").eq(i).focus();
                    houtai.hint("请填写 " + $(".add_goods_body .input_is:visible").eq(i).prev().text());
                    return false;
                }
            }
            //判断是否添加了供应商
            if($(".supplier_wrap>p").length===0){
                houtai.hint("请添加供应商");
                $("#shangpin_gongyingshang").focus();
                return false;
            }
            if (!isNaN($("#set_brand").val())) {
                houtai.hint("品牌不能只输入数字");
                $("#set_brand").focus();
                return false;
            }
            if (!isNaN($("#set_danwei").val())) {
                houtai.hint("单位不能输入数字");
                $("#set_danwei").focus();
                return false;
            }
            return true;
        },
        pinpai_fuzhi: function (n) {// n 传过来的三级分类id
            $.ajax({
                url: ip + "index.php?s=admincms/product/specsList",
                type: "post",
                data:{
                    token:get_cookie("key"),
                    catId:n
                },
                success: function (_res) {
                    //写入操作分类table
                    var res=JSON.parse(_res);
                    console.log(res);
                    if(res.errno===0){
                        var string_brand="";
                        if (res.data.brand.length > 0) {
                            $.each(res.data.brand, function (i, o) {
                                string_brand += '<li><a >' + o.names + '</a><p style="display:none;">' + o.bid + '</p></li>';
                            });
                        }
                        $("#down_menu").empty().append(string_brand);
                        var string_specs="";
                        if (res.data.specs.length > 0) {
                            $.each(res.data.specs, function (i, o) {
                                string_specs += '<li><a >' + o.unit + '</a> <p style="display:none;">' + o.sid + '</p></li>';
                            });
                        }
                        $("#down_menu_guige").empty().append(string_specs);
                        var string_color="";
                        if (res.data.color.length > 0) {
                            $.each(res.data.color, function (i, o) {
                                string_color += '<li><a >' + o.names + '</a> <p style="display:none;">' + o.id + '</p></li>';
                            });
                        }
                        $("#down_menu_color").empty().append(string_color);
                    }
                },
                error:function () {
                    houtai.hint("失败！！");
                }

            });

        },
        chushi_class: function () {
            $.ajax({
                url: ip + "index.php?s=admincms/product/product",
                async: false,
                type: "post",
                data: {
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        houtai.arr = res.data;
                        if (!sessionStorage.one) {
                            sessionStorage.one = houtai.arr[0].pid;
                        }
                        for (var ii = 0, string11 = "", string22 = "<option value=''>全部</option>", string33 = "<option value=''>全部</option>"; ii < houtai.arr.length; ii++) {
                            string11 += '<option value="' + houtai.arr[ii].pid + '">' + houtai.arr[ii].typesnames + '</option>';
                            if (houtai.arr[ii].pid == sessionStorage.one) {
                                for (var aa = 0; aa < houtai.arr[ii].activity_list.length; aa++) {
                                    string22 += '<option value="' + houtai.arr[ii].activity_list[aa].cid + '">' + houtai.arr[ii].activity_list[aa].classnames + '</option>';

                                }
                            }
                        }
                        $("#select1").empty().append(string11);
                        $("#select2").empty().append(string22);
                        $("#select3").empty().append('<option value="">全部</option>');
                        $("#select1").val(sessionStorage.one);
                    }
                },
                error: function () {
                    houtai.hint("初始类型失败了！！");
                }
            });
        },
        chushi_danwei:function () {
            var arr = getarr(localStorage.arr_danwei);
            var string_danwei="";
            var string_chicun="";
            $.each(arr, function (i, o) {
                string_danwei += '<li><a >' + o + '</a> <b title="删除" class="glyphicon glyphicon-minus"></b></li>';
            });
            $("#down_menu_danwei").empty().append(string_danwei);
            var arr_chicun = getarr(localStorage.arr_chicun);
            $.each(arr_chicun, function (i, o) {
                string_chicun += '<li><a >' + o + '</a> <b title="删除" class="glyphicon glyphicon-minus"></b></li>';
            });
            $("#down_menu_chicun").empty().append(string_chicun);
        },
        shop_list_ajax: function (page_number) {
            var n = page_number===undefined ? houtai.list_ajax_page=1 : page_number;
            var ispring=n!==0;
            $.ajax({
                url: ip + "index.php?s=admincms/product/getProductList",
                type: "post",
                async:ispring,
                data: {
                    page: n,
                    pid: houtai.linshi_search.class1,
                    cid: houtai.linshi_search.class2,
                    catId:houtai.linshi_search.class3,
                    state: houtai.linshi_search.state,
                    search: houtai.linshi_search.search,
                    supplier:houtai.linshi_search.supplier,
                    types:houtai.linshi_search.types,
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    console.log(res);
                    if(ispring){
                        houtai.table_string(res);
                        $("#page").sdpagination({
                            boxClass: 'sdpagination',
                            totalCount: res.totapage,           //总条数
                            pageSize: 10,                //每页显示
                            pageIndex: n,                //当前页数
                            preText: '上页',                                  //上一页按钮显示的字符
                            nextText: '下页',                                 //下一页按钮显示的字符
                            firstText: '首页',                                //首页按钮显示的字符
                            lastText: '末页',                                 //末页按钮显示的字符
                            showNearby: 3,                                    //当前按钮前后按钮数
                            infoTemplet: '每页{pageSize} 共{totalCount} 当前{pageIndex}/{pageCount}',//自定义信息模板
                            pageList: [5, 10, 20],                            //设置PageSize下拉框的选择项，
                            onPageIndexChange: function (pageIndex) { //回调，点击按钮时或者输入页数时，激发onPageIndexChange事件，回调参数为 新页数、PageSize
                                houtai.list_ajax_page=pageIndex;
                                houtai.shop_list_ajax(pageIndex);
                            }
                        });
                    }else{
                        houtai.excel_table_string(res);
                    }


                }
            });
        },
        table_string: function (res) {
            // 写入table
            var string_head = "<thead><tr><th>选择</th><th>其他信息</th><th>编号</th><th>商品名称</th><th>一 / 二 / 三级分类</th><th> 商品品牌</th><th>销售价格</th><th>商品规格</th><th>商品单位</th><th>商品尺寸</th><th>商品颜色</th><th>自营</th><th>低报警量</th><th>商品图片</th ><th>操作</th></tr></thead>";
            var string_body = "";
            if (res.resStatus === 0) {
                $.each(res.data, function (i, o) {
                    var imgs_string = "";
                    var detial_string="";
                    var ziying_string=o.goodsTypes===0?"自营":"三方";

                    if (o.imgall[0].img !== 0) {
                        $.each(o.imgall, function (i, o) {
                            imgs_string += '<p>' + o.img + '</p><b>' + o.imgid + '</b>';
                        });
                    }

                        $.each(o.groupImg, function (i, o) {
                            detial_string += '<span>' + o.sort+ '</span><p>' + o.img + '</p><b>' + o.id + '</b>';
                        });

                    var down_line = o.State === 0 ? '<i class="glyphicon glyphicon-saved btn btn-info btn-xs down_line">下架</i>' : '<i class="glyphicon glyphicon-open btn btn-success btn-xs up_line">上架</i>';
                    var is_hot = o.mark === 1 ? '<i style="background:#fff;padding:2px 15px;" class="glyphicon glyphicon-fire btn btn-default btn-xs down_hot"></i>' : '<i style="background: #fff;padding:2px 15px;" class="glyphicon glyphicon-fire btn btn-default btn-xs up_hot"></i>';
                    var other_string="";
                    $.each(o.supplier_list,function (i,o) {
                        other_string+='<div class="item_supplier">' +
                            '<p><span>编号：</span><span class="set_supplier_id">'+o.id+'</span></p>' +
                            '<p><span>供应商：</span><span class="set_supplier_name">'+o.sitenames+'</span></p>' +
                            '<p><span>地址：</span><span>'+o.address+'</span></p>' +
                            '<p><span>电话：</span><span>'+o.phone+'</span></p>' +
                            '<p><span>联系人：</span><span>'+o.name+'</span></p>' +
                            '<p><span>备注：</span><span>'+o.comment+'</span></p>' +
                            '</div>';
                    });
                    string_body += '<tr>' +
                        '<td style="vertical-align: middle" class="text-center"><input type="checkbox" style="width:20px;height:20px;"></td>' +
                        '<td style="vertical-align: middle" class="other_message"><b>点击查看</b></td>' +
                        '<td style="vertical-align: middle" class="bian_hao">' + o.id + '</td>' +
                        '<td style="vertical-align: middle" class="shangpin_name">' + o.names + '</td>' +
                        '<td style="vertical-align: middle" class="class_"><span class="hidden tid">' + o.tid + '</span><b>' + o.types + ' / </b><span class="hidden cid">' + o.cid + '</span><b>' + o.class + '</b><span class="hidden catid">' + o.catId + '</span><b> / ' + o.catName + '</b></td>' +
                        '<td style="vertical-align: middle" class="shangpin_pinpai">' + o.brand + '</td>' +
                        '<td style="vertical-align: middle" class="shangpin_price"><span>' + o.price + '</span></td>' +
                        '<td style="vertical-align: middle" class="shangping_guige">' + o.specs + '</td>' +
                        '<td style="vertical-align: middle" class="shangping_danwei">' + o.unit + '</td>' +
                        '<td style="vertical-align: middle" class="shangping_chicun">' + o.size + '</td>' +
                        '<td style="vertical-align: middle" class="shangping_color">' + o.color + '</td>' +
                        '<td style="vertical-align: middle" class="shangping_isziying"><span class="hidden">'+o.goodsTypes+'</span>' + ziying_string + '</td>' +
                        '<td style="vertical-align: middle" class="shangping_baojingliang">' + o.warnAmount + '</td>' +
                        '<td style="vertical-align: middle" class="shangpin_img"><img style="width: 50px" src="' + o.imgpath + '" alt=""></td>' +
                        '<td style="display:none;" class="shangpin_imgs">' + imgs_string + '</td>' +
                        '<td style="display:none;" class="shangpin_detial_imgs">' + detial_string + '</td>' +
                        '<td style="vertical-align: middle;width: 200px;" class="text-center"> <b class="btn btn-warning btn-xs glyphicon glyphicon-tags set">修</b> <span class="glyphicon glyphicon-trash btn btn-danger btn-xs remove">删</span> ' + down_line + ' ' + is_hot + '<p style="display: inline-block; margin:5px 2px;width:120px" class="btn btn-default btn-block erweima">加入二维码</p><p style="display:inline-block;margin:5px 2px;width: 50px;" class="btn btn-default btn-block record">记录</p></td>' +
                        '</tr><tr style="display: none" class="other_message_tr"><td colspan="15"><div><p><span>VR连接：</span><span class="VRlink">'+(o.link?o.link:'')+'</span></p></div>'+other_string+'</td></tr>';
                });
            } else {
                string_body = "<tr class='text-center'><td colspan='14'>没有数据</td></tr>";
            }

            $("#shangpin_table").empty().append(string_head + string_body);
        },
        excel_table_string: function (res) {
            // 写入table
            var string_head = "<thead><tr><th>编号</th><th>商品名称</th><th>一级分类 </th > <th> 二级分类 </th><th>三级分类</th><th> 商品品牌</th><th>销售价格</th><th>商品规格</th><th>商品单位</th><th>商品尺寸</th><th>商品颜色</th></tr></thead>";
            var string_body = "";
            if (res.resStatus === 0) {
                $.each(res.data, function (i, o) {
                    string_body += '<tr>' +
                        '<td style="vertical-align: middle" class="bian_hao">' + o.id + '</td>' +
                        '<td style="vertical-align: middle" class="shangpin_name">' + o.names + '</td>' +
                        '<td style="vertical-align: middle" class="class_one"><b>' + o.types + '</b></td>' +
                        '<td style="vertical-align: middle" class="class_two"><b>' + o.class + '</b></td>' +
                        '<td style="vertical-align: middle" class="class_three">' + o.catName+ '</td>' +
                        '<td style="vertical-align: middle" class="shangpin_pinpai">' + o.brand + '</td>' +
                        '<td style="vertical-align: middle" class="shangpin_price"><span>' + o.price + '</span></td>' +
                        '<td style="mso-number-format:\'\\@\';vertical-align: middle" class="shangping_guige">' + o.specs + '</td>' +
                        '<td style="vertical-align: middle" class="shangping_danwei">' + o.unit + '</td>' +
                        '<td style="mso-number-format:\'\\@\';vertical-align: middle" class="shangping_chicun">' + o.size + '</td>' +
                        '<td style="vertical-align: middle" class="shangping_color">' + o.color + '</td>' +
                        '</tr>';
                });
            } else {
                string_body = "<tr class='text-center'><td colspan='14'>没有数据</td></tr>";
            }

            $("#shangpin_table").empty().append(string_head + string_body);
        },
        huoqu_url: function (file,i) {
            var form_reader = new FileReader();
            form_reader.onload = function (e) {
                $(".img_wrap").append("<img data-id='"+i+"' src='" + e.target.result + "'/>");
            };
            form_reader.readAsDataURL(file);
        },
        huoqu_url_detial: function (file,i) {
            var form_reader = new FileReader();
            form_reader.onload = function (e) {
                $(".img_wrap_detial").append("<img data-id='"+i+"' src='" + e.target.result + "'/>");
            };
            form_reader.readAsDataURL(file);
        },
        huoqu_url_main: function (file) {
            var form_reader = new FileReader();
            form_reader.onload = function (e) {
                $(".img_wrap_main").append("<img src='" + e.target.result + "'/>");
            };
            form_reader.readAsDataURL(file);
        },
        xiugai: function () {
            if (houtai.jiancha()) {
                $(".loading").fadeIn(200);
                var form_data = new FormData($("#form")[0]);
                for (var i = 0; i < $("#input_file")[0].files.length; i++) {
                    form_data.append("imgs" + i, $("#input_file")[0].files[i]);
                }
                for (var a = 0; a < $("#input_file_detial")[0].files.length; a++) {
                    form_data.append("groupImg" + a, $("#input_file_detial")[0].files[a]);
                }
                form_data.append("imgs_main", $("#input_file_main")[0].files[0]);
                form_data.append("length", $("#input_file")[0].files.length);
                form_data.append("groupLength", $("#input_file_detial")[0].files.length);
                var supplier_arr=[];
                $.each($(".supplier_wrap>p  .supplier_val"),function () {
                    supplier_arr.push($(this).text());
                });
                form_data.append("supplier",supplier_arr);
                form_data.append("tid", $.trim($("#set-select1").val()));

                form_data.append("cid", $.trim($("#set-select2").val()));
                form_data.append("catId",$.trim($("#set-select3").val()) );
                form_data.append("price",$.trim($("#set_price").val()) );

                var sid = $.trim($("#set_guige").val());
                form_data.append("sid", sid);

                var bid = $.trim($("#set_brand").val());
                form_data.append("bid", bid);

                form_data.append("names", $.trim($("#set_name").val()));


                form_data.append("unit", $.trim($("#set_danwei").val()));

                form_data.append("size", $.trim($("#set_chicun").val()));
                form_data.append("color", $.trim($("#set_color").val()));
                form_data.append("goodsTypes", $.trim($("#set_isziying").val()));
                form_data.append("warnAmount", $("#set_baojingliang").val());
                form_data.append("link", $("#set_link").val());

                form_data.append("id", houtai.linshi_id);
                form_data.append("token", get_cookie("key"));
                form_data.append("tp", "alter");

                $.ajax({
                    url: ip + "index.php?s=admincms/product/opto",
                    data: form_data,
                    type: "post",
                    success: function (_res) {
                        var res = JSON.parse(_res);
                        if (res.resStatus === 0) {
                            var arr = getarr(localStorage.arr_danwei);
                            for (var i = 0; i < arr.length; i++) {
                                if (arr[i] === $.trim($("#set_danwei").val())) {
                                    break;
                                }
                            }
                            if (i === arr.length) {
                                arr.push($.trim($("#set_danwei").val()));

                            }
                            setarr(arr);

                            var arr_chicun = getarr(localStorage.arr_chicun);
                            for (var i1 = 0; i1 < arr_chicun.length; i1++) {
                                if (arr_chicun[i1] === $.trim($("#set_chicun").val())) {
                                    break;
                                }
                            }
                            if (i1 === arr_chicun.length) {
                                arr_chicun.push($.trim($("#set_chicun").val()));

                            }
                            setchicun_arr(arr_chicun);
                            $(".img_wrap").empty();
                            $(".img_wrap_main").empty();
                            $(".img_wrap_detial").empty();
                            $(".loading").fadeOut(200);
                            $(".add_goods_body :input").val("");
                            $(".set_shangpin").fadeOut(200);
                            houtai.shop_list_ajax(houtai.list_ajax_page);
                            houtai.hint("<p class='text-success'>修改成功了！</p>");
                        } else if (res.resStatus === 1) {
                            houtai.hint("您并未做任何修改啊！");
                            $(".loading").fadeOut(200);
                        }else if(res.resStatus === 10){
                            houtai.hint(res.message);
                            $(".loading").fadeOut(200);
                        }
                    },
                    error: function (res) {
                        $(".loading").fadeOut(200);
                        houtai.hint("<p>修改失败了！</p>");
                    },
                    processData: false,  // 告诉jQuery不要去处理发送的数据
                    contentType: false   // 告诉jQuery不要去设置Content-Type请求头
                });
            }
        },
        set_img:function(){
            $.ajax({
                url: ip + 'index.php/admin/goods/groupImg/sort',
                type: "post",
                data: {
                    id:houtai.linshi_img_id,
                    sort:$.trim($('#set_img_sort').val()),
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        $("#set_img").fadeOut();
                        houtai.hint("<span style='color:#0f0;'>修改成功了?</span>");
                        if (res.data.length === 0) {
                            $("#detial_img").empty();
                            for (var i = 0; i < $("table tr>.bian_hao").length; i++) {
                                if ($("table tr>.bian_hao").eq(i).text() === houtai.linshi_id) {
                                    $("table tr>.bian_hao").eq(i)
                                        .parents("tr").find(".shangpin_detial_imgs").empty();
                                    break;
                                }
                            }
                        } else {
                            //详情图片写入修改
                            var imgsstring = "";
                            $.each(res.data, function (i, o) {
                                imgsstring += '<div><p>排序号 <span>'+o.sort+'</span></p><img src="' + o.img + '"><b>' + o.id + '</b><span class="glyphicon glyphicon-trash remove_img"></span><i class="glyphicon glyphicon-tags set_img"></i></div>';
                            });
                            $("#detial_img").empty().append(imgsstring);
                            var imgs_string = '';
                            $.each(res.data, function (i, o) {
                                imgs_string += '<span>' + o.sort+ '</span><p>' + o.img + '</p><b>' + o.id + '</b>';
                            });
                            for (var i1 = 0; i1 < $("table tr>.bian_hao").length; i1++) {
                                if ($("table tr>.bian_hao").eq(i1).text() === houtai.linshi_id) {

                                    $("table tr>.bian_hao").eq(i1)
                                        .parents("tr").find(".shangpin_detial_imgs").empty().append(imgs_string);
                                    break;
                                }
                            }
                        }

                    }else{
                        houtai.hint(res.message);
                    }
                },
                error: function () {
                    houtai.hint("图片删除失败了！！");
                }
            });
        },
        remove_detial_img:function(){
            $.ajax({
                url: ip + 'index.php/admin/goods/groupImg/dataFlagField',
                type: "post",
                data: {
                    id:houtai.linshi_img_id,
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        $("#modal_wrap").fadeOut();
                        houtai.hint("<span style='color:#0f0;'>删除成功了?</span>");
                        if (res.data.length === 0) {
                            $("#detial_img").empty();
                            for (var i = 0; i < $("table tr>.bian_hao").length; i++) {
                                if ($("table tr>.bian_hao").eq(i).text() === houtai.linshi_id) {
                                    $("table tr>.bian_hao").eq(i)
                                        .parents("tr").find(".shangpin_detial_imgs").empty();
                                    break;
                                }
                            }
                        } else {
                            //详情图片写入修改
                            var imgsstring = "";
                            $.each(res.data, function (i, o) {
                                imgsstring += '<div><p>排序号 <span>'+o.sort+'</span></p><img src="' + o.img + '"><b>' + o.id + '</b><span class="glyphicon glyphicon-trash remove_img"></span><i class="glyphicon glyphicon-tags set_img"></i></div>';
                            });
                            $("#detial_img").empty().append(imgsstring);
                            var imgs_string = '';
                            $.each(res.data, function (i, o) {
                                imgs_string += '<span>' + o.sort+ '</span><p>' + o.img + '</p><b>' + o.id + '</b>';
                            });
                            for (var i1 = 0; i1 < $("table tr>.bian_hao").length; i1++) {
                                if ($("table tr>.bian_hao").eq(i1).text() === houtai.linshi_id) {

                                    $("table tr>.bian_hao").eq(i1)
                                        .parents("tr").find(".shangpin_detial_imgs").empty().append(imgs_string);
                                    break;
                                }
                            }
                        }

                    }else{
                        houtai.hint(res.message);
                    }
                },
                error: function () {
                    houtai.hint("图片删除失败了！！");
                }
            });
        },
        remove_img: function () {
            $.ajax({
                url: ip + 'index.php?s=admincms/product/opto',
                type: "post",
                data: {
                    tp: "delimg",
                    id: houtai.linshi_id,
                    imgid: houtai.linshi_img_id,
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        $("#modal_wrap").fadeOut();
                        houtai.hint("<span style='color:#0f0;'>删除成功了?</span>");
                        if (res.data.imgall[0].img === 0) {
                            $("#other_img").empty();
                            for (var i = 0; i < $("table tr>.bian_hao").length; i++) {
                                if ($("table tr>.bian_hao").eq(i).text() === houtai.linshi_id) {
                                    $("table tr>.bian_hao").eq(i)
                                        .parents("tr").find(".shangpin_imgs").empty();
                                    break;
                                }
                            }
                        } else {
                            //其他图片写入修改
                            var imgsstring = "";
                            $.each(res.data.imgall, function (i, o) {
                                imgsstring += '<div><img src="' + o.img + '"><b>' + o.imgid + '</b><span class="glyphicon glyphicon-trash remove_img"></span></div>';
                            });
                            $("#other_img").empty().append(imgsstring);
                            var imgs_string = '';
                            $.each(res.data.imgall, function (i, o) {
                                imgs_string += '<p>' + o.img + '</p><b>' + o.imgid + '</b>';
                            });
                            for (var i1 = 0; i1 < $("table tr>.bian_hao").length; i1++) {
                                if ($("table tr>.bian_hao").eq(i1).text() === houtai.linshi_id) {

                                    $("table tr>.bian_hao").eq(i1)
                                        .parents("tr").find(".shangpin_imgs").empty().append(imgs_string);
                                    break;
                                }
                            }
                        }

                    }else{
                        houtai.hint(res.message);
                    }
                },
                error: function () {
                    houtai.hint("图片删除失败了！！");
                }
            });
        },
        down_line: function () {
            $.ajax({
                url: ip + "index.php?s=admincms/product/opto",
                type: "post",
                data: {
                    tp: "hide",
                    id: [houtai.linshi_id],
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        for (var i = 0; i < $("table tr .bian_hao").length; i++) {
                            if ($("table tr .bian_hao").eq(i).text() == houtai.linshi_id) {
                                $("#all_select>input").prop("checked", false);
                                $("table tr .bian_hao").eq(i)
                                    .parents("tr")
                                    .find(".glyphicon-saved")
                                    .removeClass("glyphicon-saved btn-info down_line")
                                    .addClass("glyphicon-open btn-success up_line")
                                    .text("上架");
                                $("#modal_wrap").fadeOut(200);
                                var name = $("table tr .bian_hao").eq(i)
                                    .parents("tr").find(".shangpin_name").text();
                                houtai.hint("<p style='color:#0f0;'>下架" + name + "成功了</p>");
                                break;
                            }
                        }

                    } else {
                        houtai.hint(res.message);
                    }
                },
                error: function () {
                    houtai.hint("下架失败了！！");
                }
            });
        },
        up_line: function () {
            $.ajax({
                url: ip + "index.php?s=admincms/product/opto",
                type: "post",
                data: {
                    tp: "show",
                    id: [houtai.linshi_id],
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        for (var i = 0; i < $("table tr .bian_hao").length; i++) {
                            if ($("table tr .bian_hao").eq(i).text() == houtai.linshi_id) {
                                $("table tr .bian_hao").eq(i)
                                    .parents("tr")
                                    .find(".glyphicon-open")
                                    .removeClass("glyphicon-open btn-success up_line")
                                    .addClass("glyphicon-saved btn-info down_line")
                                    .text("下架");
                                $("#modal_wrap").fadeOut(200);
                                var name = $("table tr .bian_hao").eq(i)
                                    .parents("tr").find(".shangpin_name").text();
                                houtai.hint("<p style='color:#0f0;'>上架" + name + "成功了</p>");
                                break;
                            }
                        }

                    } else {
                        houtai.hint(res.message);
                    }
                },
                error: function () {
                    houtai.hint("上架失败了");
                }
            });
        },
        remove: function () {
            $.ajax({
                url: ip + "index.php?s=admincms/product/opto",
                type: "post",
                data: {
                    tp: "del",
                    id: houtai.linshi_id,
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        $("#modal_wrap").fadeOut(200);
                        for (var i = 0; i < $("table tr .bian_hao").length; i++) {
                            if ($("table tr .bian_hao").eq(i).text() == houtai.linshi_id) {
                                var name = $("table tr .bian_hao").eq(i)
                                    .parents("tr").find(".shangpin_name").text();
                                houtai.hint("<p style='color:#0f0;'>删除" + name + "成功了</p>");
                                $("table tr .bian_hao").eq(i)
                                    .parents("tr")
                                    .remove();
                                break;
                            }
                        }

                    } else if (res.resStatus === 4) {
                        houtai.hint("本商品已在限时抢购中不能删除！！");
                    } else {
                        houtai.hint(res.message);
                    }

                },
                error: function () {
                    houtai.hint("操作失败了");
                }
            });
        },
        all_up: function () {
            $.ajax({
                url: ip + "index.php?s=admincms/product/opto",
                type: "post",
                data: {
                    tp: "show",
                    id: houtai.linshi_arrid,
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        for (var i = 0, name = ""; i < houtai.linshi_arrid.length; i++) {
                            for (var a = 0; a < $("table tr .bian_hao").length; a++) {
                                if ($("table tr .bian_hao").eq(a).text() == houtai.linshi_arrid[i]) {
                                    $("table tr .bian_hao").eq(a)
                                        .parents("tr")
                                        .find(".glyphicon-open")
                                        .removeClass("glyphicon-open btn-success up_line")
                                        .addClass("glyphicon-saved btn-info down_line")
                                        .text("下架");

                                    name += $("table tr .bian_hao").eq(a)
                                            .parents("tr").find(".shangpin_name").text() + (i == houtai.linshi_arrid.length - 1 ? "" : "、");
                                }
                            }

                        }
                        $("#modal_wrap").fadeOut(200);
                        houtai.hint("<p style='color:#0f0;'>上架" + name + "成功了</p>");
                    } else {
                        houtai.hint(res.message);
                    }
                },
                error: function () {
                    houtai.hint("操作失败了");
                }
            });
        },
        all_down: function () {
            $.ajax({
                url: ip + "index.php?s=admincms/product/opto",
                type: "post",
                data: {
                    tp: "hide",
                    id: houtai.linshi_arrid,
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        for (var i = 0, name = ""; i < houtai.linshi_arrid.length; i++) {
                            for (var a = 0; a < $("table tr .bian_hao").length; a++) {
                                if ($("table tr .bian_hao").eq(a).text() == houtai.linshi_arrid[i]) {
                                    $("table tr .bian_hao").eq(a)
                                        .parents("tr")
                                        .find(".glyphicon-saved")
                                        .removeClass("glyphicon-saved btn-info down_line")
                                        .addClass("glyphicon-open btn-success up_line")
                                        .text("上架");

                                    name += $("table tr .bian_hao").eq(a)
                                            .parents("tr").find(".shangpin_name").text() + (i == houtai.linshi_arrid.length - 1 ? "" : "、");
                                }
                            }
                        }
                        $("#modal_wrap").fadeOut(200);
                        houtai.hint("<p style='color:#0f0;'>下架" + name + "成功了</p>");
                    } else {
                        houtai.hint(res.message);
                    }
                },
                error: function () {
                    houtai.hint("操作失败了");
                }
            });
        },
        up_hot: function () {
            $.ajax({
                url: ip + "index.php?s=admincms/product/marks",
                type: "post",
                data: {
                    id: houtai.linshi_id,
                    mark: 1,
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        for (var i = 0; i < $("table tr .bian_hao").length; i++) {
                            if ($("table tr .bian_hao").eq(i).text() == houtai.linshi_id) {
                                $("table tr .bian_hao").eq(i)
                                    .parents("tr")
                                    .find(".up_hot")
                                    .removeClass("up_hot")
                                    .addClass("down_hot");
                                $("#modal_wrap").fadeOut(200);
                                var name = $("table tr .bian_hao").eq(i)
                                    .parents("tr").find(".shangpin_name").text();
                                houtai.hint("<p style='color:#0f0;'>" + name + "已改为<span style='color:#f10;'>热卖</span></p>");
                                break;
                            }
                        }

                    } else {
                        houtai.hint(res.message);
                    }
                },
                error: function () {
                    houtai.hint("操作失败了");
                }
            });
        },
        down_hot: function () {
            $.ajax({
                url: ip + "index.php?s=admincms/product/marks",
                type: "post",
                data: {
                    id: houtai.linshi_id,
                    mark: 0,
                    token: get_cookie("key")
                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    if (res.resStatus === 0) {
                        for (var i = 0; i < $("table tr .bian_hao").length; i++) {
                            if ($("table tr .bian_hao").eq(i).text() == houtai.linshi_id) {
                                $("table tr .bian_hao").eq(i)
                                    .parents("tr")
                                    .find(".down_hot")
                                    .removeClass("down_hot")
                                    .addClass("up_hot");
                                $("#modal_wrap").fadeOut(200);
                                var name = $("table tr .bian_hao").eq(i)
                                    .parents("tr").find(".shangpin_name").text();
                                houtai.hint("<p style='color:#0f0;'>" + name + "已改为<span style='color:#f10;'>非热卖</span></p>");
                                break;
                            }
                        }

                    } else {
                        houtai.hint(res.message);
                    }
                },
                error: function () {
                    houtai.hint("操作失败了");
                }
            });
        },
        record_ajax: function (page_number) {
            var n = page_number ? page_number : 1;
            $.ajax({
                url: ip + "index.php?s=admincms/logproduct/showLog",
                type: "post",
                data: {
                     id:houtai.linshi_id,
                    token: get_cookie("key"),
                    page:n,
                    types:houtai.linshi_search.type,
                    time_start: houtai.linshi_search.time_start,
                    time_end: houtai.linshi_search.time_end

                },
                success: function (_res) {
                    var res = JSON.parse(_res);
                    console.log(res);
                    houtai.record_string(res);
                    $("#page1").sdpagination({
                        boxClass: 'sdpagination',
                        totalCount: res.totapage,           //总条数
                        pageSize: 10,                //每页显示
                        pageIndex: n,                //当前页数
                        preText: '上页',                                  //上一页按钮显示的字符
                        nextText: '下页',                                 //下一页按钮显示的字符
                        firstText: '首页',                                //首页按钮显示的字符
                        lastText: '末页',                                 //末页按钮显示的字符
                        showNearby: 3,                                    //当前按钮前后按钮数
                        infoTemplet: '每页{pageSize} 共{totalCount} 当前{pageIndex}/{pageCount}',//自定义信息模板
                        pageList: [5, 10, 20],                            //设置PageSize下拉框的选择项，
                        onPageIndexChange: function (pageIndex) { //回调，点击按钮时或者输入页数时，激发onPageIndexChange事件，回调参数为 新页数、PageSize
                            houtai.record_ajax(pageIndex);
                        }
                    });

                }
            });
        },
        record_string: function (res) {
            // 写入table
            var string_head = "<thead><tr><th>操作人</th><th>操作类型</th><th>操作时间</th></tr></thead>";
            var string_body = "";
            if (res.resStatus === 0) {
                $.each(res.data, function (i, o) {
                    var string1 = "";
                    var string2="";
                    var btn1="";
                    var btn2="";
                    if (o.type_n ==="alter"||o.type_n==="add") {
                        btn1="<span style='margin-left:10px;cursor:pointer;' class='glyphicon glyphicon-chevron-down'></span>";
                        btn2='class="btn1"';
                        var supplier_sring="";
                        $.each(o.obj.supplier,function (i,o) {
                            supplier_sring+= '<p><span>供应商 '+(i+1)+'：</span><span>' + o.sitenames + '</span></p>';
                        });
                        string1 = '<tr style="display: none">' +
                            '<td colspan="3" style="vertical-align: middle;background-color: rgb(251,251,244);text-align:start;" class="record_message">' +
                            '<p><span>产品名称：</span><span>' + o.obj.names + '</span></p>' +
                            '<p><span>别名：</span><span>' + o.obj.other_name + '</span></p>' +
                            '<p><span>销售价格：</span><span>' + o.obj.price + '</span></p>' +
                            '<p><span>一级分类：</span><span>' + o.obj.tid + '</span></p>' +
                            '<p><span>二级分类：</span><span>' + o.obj.cid + '</span></p>' +
                            '<p><span>品牌：</span><span>' + o.obj.brand + '</span></p>' +
                            '<p><span>规格：</span><span>' + o.obj.specs + '</span></p>' +
                            '<p><span>尺寸：</span><span>' + o.obj.size + '</span></p>' +
                            '<p><span>颜色：</span><span>' + o.obj.color + '</span></p>' +
                            '<p><span>单位：</span><span>' + o.obj.unit + '</span></p>' +
                            supplier_sring+
                            '</td>' +
                            '</tr>';
                    }else if(o.type_n === "time"){
                        btn1="<span style='margin-left:10px;cursor:pointer;' class='glyphicon glyphicon-chevron-down'></span>";
                        btn2='class="btn1"';
                        if(o.obj.type_n==="add"||o.obj.type_n==="alter"){
                            string2='<div>' +
                                '<p><span>价格：</span><span>'+o.obj.obj.price+'</span></p>' +
                                '<p><span>时间：</span><span>'+o.obj.obj.time+'</span></p>' +
                                '<p><span>序号：</span><span>'+o.obj.obj.index+'</span></p>' +
                                '</div>';
                        }

                        string1 = '<tr style="display:none">' +
                            '<td colspan="3" style="vertical-align: middle;background-color: rgb(251,251,244);text-align:start;" class="record_message">' +
                            '<p style="margin-bottom: 8px;"><span>类型：</span><span>' + o.obj.type+ '</span></p>' +string2+
                            '</td>' +
                            '</tr>';
                    }
                    string_body += '<tr '+btn2+'>' +
                        '<td style="vertical-align: middle" class="record_name">' + o.name + '</td>' +
                        '<td style="vertical-align: middle" class="record_type">' + o.type +btn1+ '</td>' +
                        '<td style="vertical-align: middle" class="record_time">' + o.time + '</td>' +
                        '</tr>';
                    string_body += string1;
                });
            } else {
                string_body = "<tr class='text-center'><td colspan='14'>没有数据</td></tr>";
            }

            $("#supervise_record table").empty().append(string_head + string_body);
        },
        control_type_ajax:function () {
            $.ajax({
                url:ip+"index.php?s=admincms/logproduct/logListQuery",
                type:"post",
                data:{
                  token:get_cookie("key")
                },
                success:function (_res) {
                    var res=JSON.parse(_res);
                    if(res.resStatus===0){
                        var string1='<option value="">全部</option>';
                        $.each(res.data,function (i,o) {
                            string1+='<option value="'+o.types+'">'+o.names+'</option>';
                        });
                        $("#taocan_select1").empty().append(string1);
                    }

                },
                error:function () {
                   houtai.hint("操作类型请求失败！！");
                }
            });
        },
        gongyingshang_ajax:function () {
            $.ajax({
                url: ip + "index.php?s=admincms/supplier/show",
                type: "post",
                data:{
                    token:get_cookie("key")
                },
                success: function (_res) {
                    var res=JSON.parse(_res);
                    if(res.resStatus===0){
                        var set_string='<option value="">请选择</option>';
                        var seller_string='<option value="">全部</option>';
                        $.each(res.data,function (i,o) {
                            set_string+='<option value="'+o.id+'">'+o.sitenames+'</option>';
                            seller_string+='<option value="'+o.id+'">'+o.sitenames+'</option>';

                        });
                        $("#shangpin_gongyingshang").empty().append(set_string);
                        $("#seller").empty().append(seller_string);
                    }else{
                        houtai.hint("供应商请求失败！！");
                    }
                },
                error:function () {
                    houtai.hint("供应商请求失败！！");
                }

            });
        }
    };
    // 初始类
    houtai.chushi_class();
    houtai.chushi_danwei();
    //供应商列表请求
    houtai.gongyingshang_ajax();
    //操作类型列表请求
    houtai.control_type_ajax();
    // 搜索时临时存放
    houtai.linshi_search.class1 = $("#select1").val();
    // 请求数据
    houtai.shop_list_ajax();
    //时间插件
    $('#input_time').daterangepicker({
        timePicker: true,
        timePickerIncrement: 30,
        locale: {
            format: 'YYYY-MM-DD HH:mm',
            applyLabel: '应用',
            cancelLabel: '取消',
            daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],
            monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]
        }
    });
    $("#input_time_btn").bind("click", function () {
        $("#input_time").click();
    });
    // 导出excel
    $("#excel_btn").bind("click",function () {
        if($("#shangpin_table tr:not(.other_message_tr):last>td").length>1){
            houtai.shop_list_ajax(0);
            var title=$("#select1>option:selected").text()+"-"+$("#select2>option:selected").text();
            houtai.excel($("#shangpin_table")[0],title);
        }else{
            houtai.hint("没有数据怎么导出啊?");
        }

    });
    $("#excel_btn").bind("click",function () {});
    console.log($("#excel_btn").data("events"));
    // 一级下拉事件
    $("#select1").bind("change", function () {
        sessionStorage.one=$(this).val();
        for (var b = 0,string2="<option value=''>全部</option>",string3="<option value=''>全部</option>"; b < houtai.arr.length; b++) { //循环分类查找对应的子集
            if (houtai.arr[b].pid == sessionStorage.one) {
                sessionStorage.two = houtai.arr[b].activity_list[0].cid; //记录这次操作
                sessionStorage.three = houtai.arr[b].activity_list[0].cats_list[0]&&houtai.arr[b].activity_list[0].cats_list[0].catId; //记录这次操作
                for (var a = 0; a < houtai.arr[b].activity_list.length; a++) {
                    string2 += '<option value="' + houtai.arr[b].activity_list[a].cid + '">' + houtai.arr[b].activity_list[a].classnames + '</option>';
                }
                break;
            }
        }
        $("#select2").empty().append(string2);
        $("#select3").empty().append('<option value="">全部</option>');
        houtai.linshi_search.class1 = $("#select1").val();
        houtai.linshi_search.class2 =$("#select2").val();
        houtai.linshi_search.class3 = $("#select3").val();
        houtai.linshi_search.state =$("#select4").val();
        houtai.linshi_search.supplier=$("#seller").val();
        houtai.linshi_search.types=$("#isAutotrophy").val();
        houtai.linshi_search.search = "";
        houtai.shop_list_ajax();
    });
    // 二级下拉事件
    $("#select2").bind("change", function () {
        if($(this).val()===""){
            $("#select3").empty().append('<option value="">全部</option>');
        }else{
            for (var b = 0,string3="<option value=''>全部</option>"; b < houtai.arr.length; b++) { //循环分类查找对应的子集
                if (houtai.arr[b].pid == sessionStorage.one) {
                    for (var a = 0; a < houtai.arr[b].activity_list.length; a++) {
                        if (houtai.arr[b].activity_list[a].cid == $(this).val()) {
                            for (var bb = 0; bb < houtai.arr[b].activity_list[a].cats_list.length; bb++) {
                                string3 += '<option value="' + houtai.arr[b].activity_list[a].cats_list[bb].catId + '">' + houtai.arr[b].activity_list[a].cats_list[bb].catName + '</option>';
                            }
                            $("#select3").empty().append(string3);
                            break;
                        }
                    }
                    break;
                }
            }
        }

        houtai.linshi_search.class1 = $("#select1").val();
        houtai.linshi_search.class2 =$("#select2").val();
        houtai.linshi_search.class3 = $("#select3").val();
        houtai.linshi_search.state = $("#select4").val();
        houtai.linshi_search.supplier=$("#seller").val();
        houtai.linshi_search.types=$("#isAutotrophy").val();
        houtai.linshi_search.search = "";
        houtai.shop_list_ajax();
    });
    // 三级下拉事件
    $("#select3").bind("change", function () {
        houtai.linshi_search.class1 = $("#select1").val();
        houtai.linshi_search.class2 = $("#select2").val();
        houtai.linshi_search.class3 = $("#select3").val();
        houtai.linshi_search.state = $("#select4").val();
        houtai.linshi_search.supplier=$("#seller").val();
        houtai.linshi_search.types=$("#isAutotrophy").val();
        houtai.linshi_search.search = "";
        houtai.shop_list_ajax();
    });
    // 状态下拉事件
    $("#select4").bind("change", function () {
        houtai.linshi_search.class1 = $("#select1").val();
        houtai.linshi_search.class2 = $("#select2").val();
        houtai.linshi_search.class3 = $("#select3").val();
        houtai.linshi_search.state = $(this).val();
        houtai.linshi_search.supplier=$("#seller").val();
        houtai.linshi_search.types=$("#isAutotrophy").val();
        houtai.linshi_search.search = "";
        houtai.shop_list_ajax();
    });
    // 搜索本类
    $("#search_ben").bind("click", function () {
        if ($("#search_input").val() === "") {
            houtai.hint("请输入再搜索");
            $("#search_input").focus();
        } else {
            houtai.linshi_search.class1 = $("#select1").val();
            houtai.linshi_search.class2 = $("#select2").val();
            houtai.linshi_search.state = $("#select4").val();
            houtai.linshi_search.search = $.trim($("#search_input").val());
            houtai.shop_list_ajax();
        }

    });
    // 搜索全站
    $("#search_all").bind("click", function () {
        if ($("#search_input").val() === "") {
            houtai.hint("请输入再搜索");
            $("#search_input").focus();
        } else {
            houtai.linshi_search.class1 = "";
            houtai.linshi_search.class2 = "";
            houtai.linshi_search.state = "";
            houtai.linshi_search.search = $.trim($("#search_input").val());
            houtai.shop_list_ajax();
        }
    });
    //按供应商搜索
    $("#seller").bind("change", function () {
        houtai.linshi_search.class1 = $("#select1").val();
        houtai.linshi_search.class2 = $("#select2").val();
        houtai.linshi_search.class3 = $("#select3").val();
        houtai.linshi_search.state =  $("#select4").val();
        houtai.linshi_search.supplier=$("#seller").val();
        houtai.linshi_search.types=$("#isAutotrophy").val();
        houtai.linshi_search.search = "";
        houtai.shop_list_ajax();
    });
    //自营所搜
    $("#isAutotrophy").bind("change", function () {
        houtai.linshi_search.class1 = $("#select1").val();
        houtai.linshi_search.class2 = $("#select2").val();
        houtai.linshi_search.class3 = $("#select3").val();
        houtai.linshi_search.state =  $("#select4").val();
        houtai.linshi_search.supplier=$("#seller").val();
        houtai.linshi_search.types=$("#isAutotrophy").val();
        houtai.linshi_search.search = "";
        houtai.shop_list_ajax();
    });
    // 修改一级下拉事件
    $("#set-select1").bind("change", function () {
        for (var b = 0,string2="",string3=""; b < houtai.arr.length; b++) { //循环分类查找对应的子集
            if (houtai.arr[b].pid == $(this).val()) {
                for (var a = 0; a < houtai.arr[b].activity_list.length; a++) {
                    string2 += '<option value="' + houtai.arr[b].activity_list[a].cid + '">' + houtai.arr[b].activity_list[a].classnames + '</option>';
                    if(houtai.arr[b].activity_list[a].cid == houtai.arr[b].activity_list[0].cid ){
                        for(var bb=0;bb<houtai.arr[b].activity_list[a].cats_list.length;bb++){
                            string3 += '<option value="' +houtai.arr[b].activity_list[a].cats_list[bb].catId+ '">' + houtai.arr[b].activity_list[a].cats_list[bb].catName+ '</option>';
                        }
                        $("#set-select3").empty().append(string3);
                    }
                }
                break;
            }
        }
        $("#set-select2").empty().append(string2);
        houtai.pinpai_fuzhi($("#set-select3").val());
    });
    // 修改二级下拉事件
    $("#set-select2").bind("change", function () {
        for (var b = 0,string3=""; b < houtai.arr.length; b++) { //循环分类查找对应的子集
            if (houtai.arr[b].pid == $("#set-select1").val() ) {
                for (var a = 0; a < houtai.arr[b].activity_list.length; a++) {
                    if (houtai.arr[b].activity_list[a].cid == $(this).val()) {
                        for (var bb = 0; bb < houtai.arr[b].activity_list[a].cats_list.length; bb++) {
                            string3 += '<option value="' + houtai.arr[b].activity_list[a].cats_list[bb].catId + '">' + houtai.arr[b].activity_list[a].cats_list[bb].catName + '</option>';
                        }
                        $("#set-select3").empty().append(string3);
                        break;
                    }
                }
                break;
            }
        }
        houtai.pinpai_fuzhi($("#set-select3").val());
    });
    // 修改三级下拉事件
    $("#set-select3").bind("change", function () {
        houtai.pinpai_fuzhi($(this).val());
    });
    //品牌下拉
    $("#down_menu").on("click", "li", function () {
        $("#set_brand").val($(this).find("a").text());
    });
    // 规格下拉
    $("#down_menu_guige").on("click", "li", function () {
        $("#set_guige").val($(this).find("a").text());
    });
    // 单位下拉
    $("#down_menu_danwei").on("click", "li", function () {
        $("#set_danwei").val($(this).text());
    });
    // 单位删除
    $("#down_menu_danwei").on("click", "b", function (e) {
        e.stopPropagation();
        var arr = getarr(localStorage.arr_danwei);
        arr.splice($(this).parents("li").index(), 1);
        setarr(arr);
        $(this).parents("li").remove();
    });
    // 尺寸下拉
    $("#down_menu_chicun").on("click", "li", function () {
        $("#set_chicun").val($(this).text());
    });
    // 尺寸删除
    $("#down_menu_chicun").on("click", "b", function (e) {
        e.stopPropagation();
        var arr_chicun = getarr(localStorage.arr_chicun);
        arr_chicun.splice($(this).parents("li").index(), 1);
        setchicun_arr(arr_chicun);
        $(this).parents("li").remove();
    });
    // 颜色下拉
    $("#down_menu_color").on("click", "li", function () {
        $("#set_color").val($(this).find("a").text());
    });

    // 全选事件
    $("#all_select>input").bind("click", function (e) {
        if ($(this).prop("checked")) {
            $(this).prop("checked", true);
            $("table>tbody>tr>td>input:not(':disabled')").prop("checked", true);
        } else {
            $(this).prop("checked", false);
            $("table>tbody>tr>td>input:not(':disabled')").prop("checked", false);
        }
    });
    // 全选事件
    $("#all_select>span").bind("click", function (e) {
        if ($(this).next().prop("checked")) {
            $(this).next().prop("checked", false);
            $("table>tbody>tr>td>input:not(':disabled')").prop("checked", false);
        } else {
            $(this).next().prop("checked", true);
            $("table>tbody>tr>td>input:not(':disabled')").prop("checked", true);
        }
    });
    // 单选事件
    $("table").on("click", "input", function (e) {
        if ($("table>tbody>tr>td>input:checked").length !== $("table>tbody>tr>td>input").length) {
            $("#all_select>input").prop("checked", false);
        } else {
            $("#all_select>input").prop("checked", true);
        }
    });
    // 收展事件
    $(".right-top>b").bind("click", function () {
        if ($(".content_left").is(":hidden")) {
            $(".content_left").removeClass("ishidden");
            $(".content_right").removeClass("iskuozhang");
        } else {
            $(".content_left").addClass("ishidden");
            $(".content_right").addClass("iskuozhang");
        }
    });
    // 默认图片上传按钮
    $("#up_button_main").bind("click", function () {
        $("#input_file_main").click();
    });
    // 默认图片选择时事件
    $("#input_file_main").change(function () {
        $(".img_wrap_main").empty();
        houtai.huoqu_url_main($(this)[0].files[0]);


    });
    // 其他图片上传按钮
    $("#up_button").bind("click", function () {
        $("#input_file").click();
    });
    // 其他图片选择时事件
    $("#input_file").change(function () {
        $(".img_wrap").empty();
        $.each($(this)[0].files, function (i, file) {
            houtai.huoqu_url(file,i);
        });

    });
    // 详情图片上传按钮
    $("#up_button_detial").bind("click", function () {
        $("#input_file_detial").click();
    });
    // 详情图片选择时事件
    $("#input_file_detial").change(function () {
        $(".img_wrap_detial").empty();
        $.each($(this)[0].files, function (i, file) {
            houtai.huoqu_url_detial(file,i);
        });

    });
    // 莫态框取消modal
    $("#modal_close").bind("click", function () {
        $("#modal_wrap").fadeOut(200);

    });
    // 修改取消
    $("#cancle_set").bind("click", function () {
        $(".set_shangpin").fadeOut(200);
        $(".img_wrap").empty();
        $(".img_wrap_main").empty();
        $("#input_file").val("");
        $("#input_file_main").val("");
    });
    // 图片修改取消
    $("#cancle_set_img").bind("click", function () {
        $("#set_img").fadeOut(200);
    });
    // 图片修改确认
    $("#set_images").bind("click", function () {
        houtai.set_img()
    });
    //取消记录框按钮
    $("#close_record").bind("click", function () {
        $("#supervise_record").fadeOut();
    });
    //其他信息查看展开收缩按钮
    $("table").on("click",".other_message>b",function () {
      $(this).parents("tr").next().fadeToggle();
    });
    //供应商下拉
    $("#shangpin_gongyingshang").bind("change",function () {
        if($(this).val()!==""){
            for(var i=0;i< $(".supplier_wrap .supplier_val").length;i++){
                if($(".supplier_wrap .supplier_val").eq(i).text()===$("#shangpin_gongyingshang").val()){
                    break;
                }
            }
            if(i===$(".supplier_wrap .supplier_val").length){
                $(".supplier_content").fadeIn();
                $(".supplier_wrap").append(
                    '<p>' +
                    '<b class="supplier_val">'+$(this).val()+'</b>' +
                    '<span class="supplier_index"> '+($(".supplier_wrap>p").length+1)+'</span>' +
                    '<span class="supplier_name">'+$("#shangpin_gongyingshang option:selected").text()+' </span>' +
                    '<b class="supplier_remove glyphicon glyphicon-trash"></b>' +
                    '</p>');
            }

        }

    });
    //删除临时供应商
    $(".supplier_content").on("click",".supplier_remove",function () {
        $(this).parents("p").remove();
        $.each($(".supplier_wrap>p .supplier_index"),function (i) {
            $(this).text(i+1);
        });
        $("#shangpin_gongyingshang").val("");
        if($(".supplier_wrap>p").length===0){
            $(".supplier_content").hide();

        }
    });
    // 修改
    $("table").on("click", ".set", function () {
        $(window).scrollTop(0);
        houtai.linshi_id = $(this).parents("tr").find(".bian_hao").text();
        $("#set_brand").val($(this).parents("tr").find(".shangpin_pinpai").text());
        $("#set_name").val($(this).parents("tr").find(".shangpin_name").text());
        $("#set_other_name").val($(this).parents("tr").find(".shangpin_other_name").text());
        $("#set_price").val($(this).parents("tr").find(".shangpin_price").find("span").text());
        $("#set_guige").val($(this).parents("tr").find(".shangping_guige").text());
        $("#set_danwei").val($(this).parents("tr").find(".shangping_danwei").text());
        $("#set_chicun").val($(this).parents("tr").find(".shangping_chicun").text());
        $("#set_color").val($(this).parents("tr").find(".shangping_color").text());
        $("#set_isziying").val($(this).parents("tr").find(".shangping_isziying>span").text());
        $("#set_baojingliang").val(Number($(this).parents("tr").find(".shangping_baojingliang").text()));


        for (var ii = 0, string11 = "", string22 = "", string33 = ""; ii < houtai.arr.length; ii++) {
            string11 += '<option value="' + houtai.arr[ii].pid + '">' + houtai.arr[ii].typesnames + '</option>';
            if (houtai.arr[ii].pid ==$(this).parents("tr").find(".class_").find(".tid").text()) {
                for (var aa = 0; aa < houtai.arr[ii].activity_list.length; aa++) {
                    string22 += '<option value="' + houtai.arr[ii].activity_list[aa].cid + '">' + houtai.arr[ii].activity_list[aa].classnames + '</option>';
                    if(houtai.arr[ii].activity_list[aa].cid == $(this).parents("tr").find(".class_").find(".cid").text()){
                        for(var bb=0;bb<houtai.arr[ii].activity_list[aa].cats_list.length;bb++){
                            string33 += '<option value="' +houtai.arr[ii].activity_list[aa].cats_list[bb].catId+ '">' + houtai.arr[ii].activity_list[aa].cats_list[bb].catName+ '</option>';
                        }
                        $("#set-select3").empty().append(string33);
                    }
                }
                $("#set-select2").empty().append(string22);
            }
        }
        $("#set-select1").empty().append(string11);

        $("#set-select1").val($(this).parents("tr").find(".class_").find(".tid").text());
        $("#set-select2").val($(this).parents("tr").find(".class_").find(".cid").text());
        $("#set-select3").val($(this).parents("tr").find(".class_").find(".catid").text());
        $("#set_shangpin").fadeIn(200);
        houtai.pinpai_fuzhi($("#set-select3").val());

        //主图片写入修改
        $("#main_img").empty().append("<div><img src='" + $(this).parents("tr").find(".shangpin_img").find("img").prop("src") + "'></div>");

        //其他图片写入修改
        var imgsstring = "";
        $.each($(this).parents("tr").find(".shangpin_imgs").find('p'), function (i, o) {
            imgsstring += '<div><img src="' + $(o).text() + '"><b>' + $(o).next().text() + '</b><span class="glyphicon glyphicon-trash remove_img"></span></div>';
        });
        $("#other_img").empty().append(imgsstring);

        //详情图片写入修改
        var detialstring = "";
        $.each($(this).parents("tr").find(".shangpin_detial_imgs").find('p'), function (i, o) {
            detialstring += '<div><p>排序号 <span>'+$(o).prev().text()+'</span></p><img src="' + $(o).text() + '"><b>' + $(o).next().text() + '</b><span class="glyphicon glyphicon-trash remove_img"></span><i class="glyphicon glyphicon-tags set_img"></i></div>';
        });
        $("#detial_img").empty().append(detialstring);

        //链接写入
        $("#set_link").val($(this).parents("tr").next().find("td .VRlink").text());
        //供应商信息写入
        $(".supplier_content").hide();
        $(".supplier_wrap>p").remove();
        var that=$(this).parents("tr").next().find("td>.item_supplier");
        console.log(that);
        $.each(that,function (i,o) {
            $(".supplier_content").fadeIn();
            $(".supplier_wrap").append(
                '<p>' +
                '<b class="supplier_val">'+ $(this).find(".set_supplier_id").text()+'</b>' +
                '<span class="supplier_index"> '+(i+1)+'</span>' +
                '<span class="supplier_name">'+ $(this).find(".set_supplier_name").text()+' </span>' +
                '<b class="supplier_remove glyphicon glyphicon-trash"></b>' +
                '</p>');
          $(this).find(".set_supplier_name").text();

        });

    });
    // 删除
    $("table").on("click", ".remove", function () {
        houtai.linshi_id = $(this).parents("tr").find(".bian_hao").text();
        houtai.queren_type = 0;
        if ($(this).parents("tr").find(".glyphicon-open").length > 0) {
            $("#modal_wrap").find(".modal-body").empty().append("你确定要删除<span style='color:#f10;'>" + $(this).parents("tr").find('.shangpin_name').text() + "</span>吗？");
            $("#modal_wrap").show();
        } else {
            houtai.hint("<span style='font-size:30px;color:#2aabd2;'>" + $(this).parents("tr").find(".shangpin_name").text() + "</span>" + " 已上架,请点击下架后删除！");
        }
    });
    // 上架
    $("table").on("click", ".up_line", function () {
        houtai.linshi_id = $(this).parents("tr").find(".bian_hao").text();
        houtai.queren_type = 1;
        $("#modal_wrap").find(".modal-body").empty().append("你确定要上架<span style='color:#f10;'>" + $(this).parents("tr").find('.shangpin_name').text() + "</span>吗？");
        $("#modal_wrap").show();

    });
    // 下架
    $("table").on("click", ".down_line", function () {
        houtai.linshi_id = $(this).parents("tr").find(".bian_hao").text();
        houtai.queren_type = 2;
        $("#modal_wrap").find(".modal-body").empty().append("你确定要下架<span style='color:#f10;'>" + $(this).parents("tr").find('.shangpin_name').text() + "</span>吗？");
        $("#modal_wrap").show();

    });

    // 上热卖
    $("table").on("click", ".up_hot", function () {
        houtai.linshi_id = $(this).parents("tr").find(".bian_hao").text();
        houtai.queren_type = 6;
        $("#modal_wrap").find(".modal-body").empty().append("你确定要把<span style='color:#f10;'>" + $(this).parents("tr").find('.shangpin_name').text() + "</span>改为<span style='color:#faa;'>热卖</span>吗？");
        $("#modal_wrap").show();

    });
    // 下热卖
    $("table").on("click", ".down_hot", function () {
        houtai.linshi_id = $(this).parents("tr").find(".bian_hao").text();
        houtai.queren_type = 7;
        $("#modal_wrap").find(".modal-body").empty().append("你确定要把<span style='color:#f10;'>" + $(this).parents("tr").find('.shangpin_name').text() + "</span>改为<span style='color:#faa;'>非热卖</span>吗？");
        $("#modal_wrap").show();

    });
    //二维码
    $("table").on("click", ".erweima", function () {
        houtai.linshi_id=$(this).parents("tr").find(".bian_hao").text();
        var has_item=false;
        var _name=$(this).parents("tr").find(".shangpin_name").text();
       $.each($(".name_erweima>span"),function(){
           var a=$(this).text();
          if(a===_name) {
              has_item=true;
          }
       });
       if(has_item){
           houtai.hint("已经有这个商品!!");
       }else{
           var erweima_name="erweima"+Date.now();
           $("#erweima_wrap>div").append('' +
               '<div class="item_erweima">' +
               '<div class="img_erweima '+erweima_name+'"></div> ' +
               '<p class="brand_erweima">编号：<span>'+$(this).parents("tr").find(".bian_hao").text()+'</span></p> ' +
               '<p class="brand_erweima">品牌：<span>'+$(this).parents("tr").find(".shangpin_pinpai").text()+'</span></p> ' +
               '<p class="gui_erweima">规格：<span>'+$(this).parents("tr").find(".shangping_guige").text()+'</span></p> ' +
               '<p class="name_erweima"><span>'+$(this).parents("tr").find(".shangpin_name").text()+'</span></p> ' +
               '</div>'
           );

           new QRCode($("."+erweima_name)[0], {
               text: houtai.linshi_id,
               width: 300,
               height: 300
           });
           $("#erweima_wrap").show();
       }



    });
    //打印二维码
    $("#pring_erweima").bind("click",function () {
        $(".item_erweima").css({
            "width": 340,
            "height":476,
            "padding-top": 10,
            "padding-bottom": 20,
            "float": "left",
            "border":"1px solid #888"
        });
        $(".item_erweima>p").css({
            "text-align": "center",
            "margin-bottom": 10,
            "font-size":18
        });
        $(".img_erweima").css({
            "width": 300,
           "height": 300,
            "margin":"20px 20px 20px 20px"
        });

         $("#erweima_wrap>div").jqprint();
        $("#erweima_wrap").hide();
        $("#erweima_wrap>div").empty();
    });
    //关闭二维码
    $(".close_erweima").bind("click",function () {
        $("#erweima_wrap").hide();
        $("#erweima_wrap>div").empty();
    });
    //记录查询
    $("table").on("click", ".record", function () {
        $(window).scrollTop(0);
        houtai.linshi_id = $(this).parents("tr").find(".bian_hao").text();
        houtai.record_ajax();
        $("#supervise_record").fadeIn();
    });
    //按类型搜索
    $("#taocan_select1").bind("change",function () {
      houtai.linshi_search.type=$(this).val();
      houtai.linshi_search.time_start="";
      houtai.linshi_search.time_end="";
      houtai.record_ajax();
    });
    // 按时间搜索
    $("#search_time").bind("click", function () {
        if ($.trim($("#input_time").val()) === "") {
            $("#input_time").focus();
            houtai.hint("请输入搜索内容");
        } else {
            if (houtai.click_yes()) {
                console.log($("#input_time").val());
                // 匹配的正则表达式
                var regexp = /(\d+-\d+-[^-]+)-(.+)/;
                houtai.linshi_search.type="";
                houtai.linshi_search.time_start = new Date($("#input_time").val().match(regexp)[1]).getTime() / 1000;
                houtai.linshi_search.time_end = new Date($("#input_time").val().match(regexp)[2]).getTime() / 1000;
                houtai.record_ajax();
            }
        }

    });
    //记录查询点击隐藏或展开事件
    $("#supervise_record").on("click",".btn1",function () {
     $(this).next().fadeToggle();
    });
    // 全选上架按钮
    $("#all_up").bind("click", function () {
        houtai.linshi_arrid = [];
        houtai.queren_type = 3;
        if ($("table>tbody>tr>td>input:checked").parents("tr").find(".up_line").length > 0) {
            for (var i = 0,
                     string = ""; i < $("table>tbody>tr>td>input:checked").parents("tr").find(".up_line").length; i++) {
                houtai.linshi_arrid.push($("table>tbody>tr>td>input:checked").parents("tr").find(".up_line").eq(i).parents("tr").find(".bian_hao").text());
                string += "<span style='color:#f10;'>" + (i === 0 ? '' : '、') + $("table>tbody>tr>td>input:checked").parents("tr").find(".up_line").eq(i).parents('tr').find('.shangpin_name').text() + "</span>";
            }
            $("#modal_wrap").find(".modal-body").empty().append("你确定要上架" + string + "吗？");
            $("#modal_wrap").show();
        } else {
            houtai.hint("<p>请选择您要操作的商品</p>");
        }

    });
    // 全选下架按钮
    $("#all_down").bind("click", function () {
        houtai.linshi_arrid = [];
        houtai.queren_type = 4;
        if ($("table>tbody>tr>td>input:checked").parents("tr").find(".down_line").length > 0) {
            for (var i = 0,
                     string = ""; i < $("table>tbody>tr>td>input:checked").parents("tr").find(".down_line").length; i++) {
                houtai.linshi_arrid.push($("table>tbody>tr>td>input:checked").parents("tr").find(".down_line").eq(i).parents("tr").find(".bian_hao").text());
                string += "<span style='color:#f10;'>" + (i === 0 ? '' : '、') + $("table>tbody>tr>td>input:checked").parents("tr").find(".down_line").eq(i).parents('tr').find('.shangpin_name').text() + "</span>";
            }
            $("#modal_wrap").find(".modal-body").empty().append("你确定要下架" + string + "吗？");
            $("#modal_wrap").show();
        } else {
            houtai.hint("<p>请选择您要操作的商品</p>");
        }

    });
    // 确认
    $("#confirm").bind("click", function () {
        // 删除
        if (houtai.queren_type === 0) {
            houtai.remove();
        }
        // 上架
        if (houtai.queren_type === 1) {
            houtai.up_line();
        }
        // 下架
        if (houtai.queren_type === 2) {
            houtai.down_line();
        }
        // 全部上架
        if (houtai.queren_type === 3) {
            houtai.all_up();
        }
        //全部下架
        if (houtai.queren_type === 4) {
            houtai.all_down();
        }
        //删除图片
        if (houtai.queren_type === 5) {
            if (houtai.click_yes()) {
                houtai.remove_img();
            }
        }
        //上热卖
        if (houtai.queren_type === 6) {
            houtai.up_hot();
        }
        //下热卖
        if (houtai.queren_type === 7) {
            houtai.down_hot();
        }
        //删除详情图片
        if (houtai.queren_type === 8) {
            houtai.remove_detial_img();
        }

    });
    // 修改按钮
    $("#add").bind("click", function () {
        if (houtai.click_yes()) {
            houtai.xiugai();
        }
    });
    // 删除其他图片按钮
    $("#other_img").on("click", ".remove_img", function () {
        houtai.linshi_img_id = $(this).prev().text();
        houtai.queren_type = 5;
        $(".modal-body").empty().append("您确定要删除这张图片吗？");
        $("#modal_wrap").fadeIn();
    });
    // 删除详情图片按钮
    $("#detial_img").on("click", ".remove_img", function () {
        houtai.linshi_img_id = $(this).prev().text();
        houtai.queren_type = 8;
        $(".modal-body").empty().append("您确定要删除这张图片吗？");
        $("#modal_wrap").fadeIn();
    });
    // 修改详情图片按钮
    $("#detial_img").on("click", ".set_img", function () {
        houtai.linshi_img_id = $(this).parent('div').find('b').text();
        $('#set_img_sort').val($(this).parent('div').find('p span').text())
       $("#set_img").show()
    });
    // 主图放大按钮
    $("#main_img").on("click", "img", function () {
        var imgH = $(this)[0].naturalHeight;
        var imgW = $(this)[0].naturalWidth;
        var windW = $(window).width();
        var windH = $(window).height();
        $(".img_show>img").css({
            left: $(this).offset().left,
            top: $(this).offset().top - $(window).scrollTop(),
            width: $(this).width(),
            height: $(this).height()
        });
        $(".img_show>img").attr("src", $(this).attr("src"));
        $(".img_show").fadeIn();
        if ((((imgW / imgH) > (windW / windH)) && (imgW < windW)) || (((imgW / imgH) <= (windW / windH)) && (imgH < windH))) {
            $(".img_show>img").css({
                left: (windW - imgW) / 2,
                top: (windH - imgH) / 2,
                width: imgW,
                height: imgH
            });
        } else if (((imgW / imgH) > (windW / windH)) && (imgW >= windW)) {
            $(".img_show>img").css({
                width: windW,
                height: windW * (imgH / imgW),
                top: (windH - (windW * (imgH / imgW))) / 2,
                left: 0
            });
        } else if (((imgW / imgH) <= (windW / windH)) && (imgH >= windH)) {
            $(".img_show>img").css({
                width: windH * (imgW / imgH),
                height: windH,
                left: (windW - (windH * (imgW / imgH))) / 2,
                top: 0
            });
        }
    });
    // 其他图放大按钮
    $("#other_img").on("click", "img", function () {
        $(".img_show>img").css({
            left: $(this).offset().left,
            top: $(this).offset().top - $(window).scrollTop(),
            width: $(this).width(),
            height: $(this).height()
        });
        $(".img_show>img").attr("src", $(this).attr("src"));
        $(".img_show").fadeIn();
        var imgH = $(this)[0].naturalHeight;
        var imgW = $(this)[0].naturalWidth;
        var windW = $(window).width();
        var windH = $(window).height();
        if ((((imgW / imgH) > (windW / windH)) && (imgW < windW)) || (((imgW / imgH) <= (windW / windH)) && (imgH < windH))) {
            $(".img_show>img").css({
                left: (windW - imgW) / 2,
                top: (windH - imgH) / 2,
                width: imgW,
                height: imgH
            });
        } else if (((imgW / imgH) > (windW / windH)) && (imgW >= windW)) {
            $(".img_show>img").css({
                width: windW,
                height: windW * (imgH / imgW),
                top: (windH - (windW * (imgH / imgW))) / 2,
                left: 0
            });
        } else if (((imgW / imgH) <= (windW / windH)) && (imgH >= windH)) {
            $(".img_show>img").css({
                width: windH * (imgW / imgH),
                height: windH,
                left: (windW - (windH * (imgW / imgH))) / 2,
                top: 0
            });
        }


    });
    // 详情图放大按钮
    $("#detial_img").on("click", "img", function () {
        $(".img_show>img").css({
            left: $(this).offset().left,
            top: $(this).offset().top - $(window).scrollTop(),
            width: $(this).width(),
            height: $(this).height()
        });
        $(".img_show>img").attr("src", $(this).attr("src"));
        $(".img_show").fadeIn();
        var imgH = $(this)[0].naturalHeight;
        var imgW = $(this)[0].naturalWidth;
        var windW = $(window).width();
        var windH = $(window).height();
        if ((((imgW / imgH) > (windW / windH)) && (imgW < windW)) || (((imgW / imgH) <= (windW / windH)) && (imgH < windH))) {
            $(".img_show>img").css({
                left: (windW - imgW) / 2,
                top: (windH - imgH) / 2,
                width: imgW,
                height: imgH
            });
        } else if (((imgW / imgH) > (windW / windH)) && (imgW >= windW)) {
            $(".img_show>img").css({
                width: windW,
                height: windW * (imgH / imgW),
                top: (windH - (windW * (imgH / imgW))) / 2,
                left: 0
            });
        } else if (((imgW / imgH) <= (windW / windH)) && (imgH >= windH)) {
            $(".img_show>img").css({
                width: windH * (imgW / imgH),
                height: windH,
                left: (windW - (windH * (imgW / imgH))) / 2,
                top: 0
            });
        }


    });
    // 放大图点击消失
    $(".img_show").bind("click", function () {
        $(this).fadeOut();
    });
    //退出按钮
    $("#exit").bind("click", function () {
        set_cookie("key", "", 0);
        location.href = key_address;
    });
    //头像按钮
    $(".right-top>div").bind("click", function (e) {
        $("#exit").slideToggle();
        e.stopPropagation();
    });
    $(window).bind("click", function () {
        $("#exit").slideUp();
    });
});

